package org.androidpn.server.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * entity 用户
 * 
 * @author 蔡琪
 * 
 */
@Entity
@Table(name = "tk_user")
public class User extends BaseEntity {

	private static final long serialVersionUID = -399817672477116111L;

	/**
	 * 用户状态
	 * 
	 * @author 蔡琪
	 * 
	 */
	public enum UserStatus {
		/** 可用 */
		enable,
		/** 不可用 */
		disable,
		/** 锁定 */
		locked
	}

	/** 用户名 */
	@Column(name = "username", unique = true, nullable = false, length = 16)
	private String username;

	/** 姓名 */
	@Column(name = "name", length = 16)
	private String name;

	/** 电子邮箱地址 */
	@Column(name = "email", unique = true)
	private String email;

	/** 密码 */
	@Column(name = "password", length = 64)
	private String password;

	/** 状态 */
	@Column(name = "status")
	private UserStatus status;

	/** 上次登录IP */
	@Column(name = "last_login_ip")
	private String lastLoginIp;

	/** 是否在线 */
	@Column(name = "online")
	private Boolean online;

	/** 拥有角色 */
	@OneToMany(mappedBy = "user", cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	private Set<Role> roles = new HashSet<Role>();

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public UserStatus getStatus() {
		return status;
	}

	public void setStatus(UserStatus status) {
		this.status = status;
	}

	public String getLastLoginIp() {
		return lastLoginIp;
	}

	public void setLastLoginIp(String lastLoginIp) {
		this.lastLoginIp = lastLoginIp;
	}

	public Boolean getOnline() {
		return online;
	}

	public void setOnline(Boolean online) {
		this.online = online;
	}

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

}
